<?php
defined('IN_PHPCMS') or exit('No permission resources.');
if(!defined('CACHE_MODEL_PATH')) define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

pc_base::load_sys_class('model', '', 0);
class source_type_model extends model {
	public function __construct() {
		$this->db_config = pc_base::load_config('database');
		$this->db_setting = 'default';
		$this->table_name = 'source_type';
		parent::__construct();
	}

	/**
     * 取资源类型
     */
    public function getSource ($type,$parentid,$status = 0)
    {
    	$tree = pc_base::load_sys_class('tree');
        $where = array();
        $where['status'] = 1;
        $where['type'] = $type;
        if ($status == 1) {
            $where['parentid'] = 0;
        }
        $result = $this->select($where);
        $array = array();
        foreach($result as $r) {
            $r['cname'] = L($r['cn_name']);
            $r['selected'] = $r['id'] == $parentid ? 'selected' : '';
            $array[] = $r;
        }
        $str  = "<option value='\$id' \$selected>\$spacer \$cname</option>";
        $tree->init($array);
        $select_categorys = $tree->get_tree(0, $str);
        return $select_categorys;
    }
    
    /**
     * 根据type_id取资源类型
     */
    public function getSourceType ($type_id)
    {
        $where = array();
        $where['status'] = 1;
        $where['id'] = $type_id;
        $where['siteid'] = get_siteid();
        $result = $this->select($where);
        return $result;
    }
}
?>